<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<#if userType=="1">
					<h2>农户编辑 <small></small></h2>
				</#if>
				<#if userType=="2">
					<h2>代理商编辑 <small></small></h2>
				</#if>
				<#if userType=="3">
					<h2>业务员编辑 <small></small></h2>	
				</#if>
				<#if userType=="4">
					<h2>营业部编辑 <small></small></h2>
				</#if>
				<#if userType=="5">
					<h2>代理商业务员编辑 <small></small></h2>
				</#if>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<br/>
				<form id="postForm" data-parsley-validate class="form-horizontal form-label-left" method="post" action="${base}/gx/user/save">
					<input type="hidden" id="id" name="id" value="${((obj.id)?c)!0 }">
					<input type="hidden" name="userType" value="${(obj.userType)!userType}">
		            <input type="hidden" name="createTime" value="${(obj.createTime)!.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="updateTime" value="${.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="creator" value="${(obj.creator)!admin.userName}">
		            <input type="hidden" name="updator" value="${(obj.updator)!admin.userName}">
		            <input type="hidden" name="areaSub" value="${(obj.areaSub)!''}">
		            <input type="hidden" name="userNameOld" value="${(obj.userName)!''}">
		            <input type="hidden" name="phoneOld" value="${(obj.phone)!''}">
		            <input type="hidden" name="cardNoOld" value="${(obj.cardNo)!''}">
		            <input type="hidden" name="isChecked" value="${(obj.isChecked)!1}">
		            <input type="hidden" name="checkRemark" value="${(obj.checkRemark)!''}">
		            <#if userType=="2"||userType=="3">
		            <input type="hidden" name="belongId" value="${(obj.belongId)!0}">
		            </#if>
		            <#if userType=="1">
		            <input type="hidden" name="userNo" value="${(obj.userNo)!''}">
		            </#if>
		            <#if userType=="1"||userType=="3"||userType=="4"||userType=="5">
		            <input type="hidden" name="userLevel" value="${(obj.userLevel)!0}">
		            </#if>
		            <#if obj??>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属省 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="province" name="areaProvince.code" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listProvince as province>
	                        	<option value="${province.code}" <#if (obj.areaProvince.code==province.code)>selected="selected"</#if>>${province.cityName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属市 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="city" name="areaCity.code" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listCity as city>
	                        	<option value="${city.code}" <#if (obj.areaCity.code==city.code)>selected="selected"</#if>>${city.cityName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属区县<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="district" name="areaDistrict.code" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listDistrict as district>
	                        	<option value="${district.code}" <#if (obj.areaDistrict.code==district.code)>selected="selected"</#if>>${district.cityName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属省 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="province" name="areaProvince.code" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listProvince as province>
	                        	<option value="${province.code}">${province.cityName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属市 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="city" name="areaCity.code" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listCity as city>
	                        	<option value="${city.code}">${city.cityName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属区县<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="district" name="areaDistrict.code" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listDistrict as district>
	                        	<option value="${district.code}">${district.cityName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					</#if>
					<#if userType=="1">
					<#if obj??>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属业务员 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongId" name="belongId" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listYWY as ywy>
	                        	<option value="${ywy.id?c}" <#if (obj.belongId==ywy.id)>selected="selected"</#if>>${ywy.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属业务员 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongId" name="belongId" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listYWY as ywy>
	                        	<option value="${ywy.id?c}">${ywy.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					</#if>
					</#if>
					<#if userType=="1">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">推介人编号 <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="tjrNo" name="tjrNo" value="${(obj.tjrNo)!''}" class="form-control col-md-7 col-xs-12" readonly="readonly">
                        </div>
					</div>
					</#if>
					<#if userType=="2">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">代理编号 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userNo" name="userNo" value="${(userNo)!''}" class="form-control col-md-7 col-xs-12" readonly="readonly">
                        </div>
					</div>
					</#if>
					<#if userType=="4">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">营业部编号 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userNo" name="userNo" value="${(userNo)!''}" class="form-control col-md-7 col-xs-12" readonly="readonly">
                        </div>
					</div>
					</#if>
					<#if userType=="3"||userType=="5">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">业务员编号 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userNo" name="userNo" value="${(userNo)!''}" class="form-control col-md-7 col-xs-12" readonly="readonly">
                        </div>
					</div>
					</#if>
					<#if userType=="2">
					<#if obj??>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">代理级别 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="userLevel" name="userLevel" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listAgentLevel as agentLevel>
	                        	<option value="${agentLevel.id?c}" <#if (obj.userLevel==agentLevel.id)>selected="selected"</#if>>${agentLevel.title}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">代理级别 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="userLevel" name="userLevel" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listAgentLevel as agentLevel>
	                        	<option value="${agentLevel.id?c}">${agentLevel.title}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					</#if>
					</#if>
					<#if userType=="4">
					<#if obj??>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属代理商 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongId" name="belongId" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listDLS as dls>
	                        	<option value="${dls.id?c}" <#if (obj.belongId==dls.id)>selected="selected"</#if>>${dls.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属代理商 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongId" name="belongId" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listDLS as dls>
	                        	<option value="${dls.id?c}">${dls.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					</#if>
					</#if>
					<#if userType=="5">
					<#if obj??>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属代理商 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongDLS" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listDLS as dls>
	                        	<option value="${dls.id?c}" <#if (obj.belongId==dls.id)>selected="selected"</#if>>${dls.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属营业部 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongId" name="belongId" class="form-control select2">
                        		<option value="">请选择</option>
	                        	<#list listYYB as yyb>
	                        	<option value="${yyb.id?c}" <#if (obj.belongId==yyb.id)>selected="selected"</#if>>${yyb.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属代理商 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongDLS" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                        	<#list listDLS as dls>
	                        	<option value="${dls.id?c}">${dls.userName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属营业部 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="belongId" name="belongId" class="form-control select2">
                        		<option value="" selected="selected">请选择</option>
	                    	</select>
                        </div>
					</div>
					</#if>
					</#if>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">地址 <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="address" name="address" value="${(obj.address)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">地址经度 <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="lon" name="lon" value="${(obj.lon)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">地址纬度 <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="lat" name="lat" value="${(obj.lat)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<#if userType=="1"||userType=="2">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">用户名 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userName" name="userName" value="${(obj.userName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					</#if>
					<#if userType=="4">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">营业部名称 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userName" name="userName" value="${(obj.userName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">营业部负责人 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="realName" name="realName" value="${(obj.realName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					</#if>
					<#if userType=="3"||userType=="5">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">业务员用户名 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userName" name="userName" value="${(obj.userName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					</#if>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">密码 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="password" id="password" name="password" value="${(obj.password)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">手机号 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="phone" name="phone" value="${(obj.phone)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<#if obj??>
					<#else>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">验证码 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="checkCode" name="checkCode" class="form-control col-md-7 col-xs-7" style="width:70%;">&nbsp;
                        	<button type="button" class="btn btn-success " id="getCheckCode">获取验证码</button>
                        </div>
					</div>
					</#if>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">身份证号 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="cardNo" name="cardNo" value="${(obj.cardNo)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<#if userType=="1"||userType=="3"||userType=="5">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">真实姓名 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="realName" name="realName" value="${(obj.realName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					</#if>
						<#if userType=="2">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">负责人姓名 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="realName" name="realName" value="${(obj.realName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					</#if>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">性别 <span class="required"></span>
                        </label>
                        <#if obj??>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	男：<input type="radio" class="flat" name="sex" value="男" <#if (obj.sex=='男')>checked="checked"</#if>/>&nbsp;
                        	女：<input type="radio" class="flat" name="sex" value="女" <#if (obj.sex=='女')>checked="checked"</#if>/>
                        </div>
                        <#else>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	男：<input type="radio" class="flat" name="sex" value="男" checked="checked"/>&nbsp;
                        	女：<input type="radio" class="flat" name="sex" value="女"/>
                        </div>
                        </#if>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">生日 <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="birth" name="birth" value="${(obj.birth)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">年龄 <span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="age" name="age" value="${(obj.age)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">户口本号 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="regNo" name="regNo" value="${(obj.regNo)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">户主 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="regMain" name="regMain" value="${(obj.regMain)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">身份证图片 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="file" id="cardIcon_dropify" name="file1" class="dropify" data-default-file="${imagePath}${(obj.cardIcon)!''}" />
                            <input type="hidden" name="cardIcon" id="cardIcon" value="${(obj.cardIcon)!''}">
                            <input type="hidden" name="cardIconOld" id="cardIconOld" value="${(obj.cardIcon)!''}">
                        </div>
					</div>
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">户口本图片 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="file" id="regIcon_dropify" name="file2" class="dropify" data-default-file="${imagePath}${(obj.regIcon)!''}" />
                            <input type="hidden" name="regIcon" id="regIcon" value="${(obj.regIcon)!''}">
                            <input type="hidden" name="regIconOld" id="regIconOld" value="${(obj.regIcon)!''}">
                        </div>
					</div>
					<div class="ln_solid"></div>
					<div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<button type="button" class="btn btn-success" id="submit">保存</button>
							<button type="button" class="btn btn-primary" id="goBack">返回</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(function() {
	//iCheck
	if ($("input.flat")[0]) {
		$(document).ready(function () {
	    	$('input.flat').iCheck({
	        	checkboxClass: 'icheckbox_flat-green',
	        	radioClass: 'iradio_flat-green'
	        });
	    });
	}
	// /iCheck
	laydate.render({elem: '#birth',type: 'date'});
	//select2
	$(".select2").select2({width: "100%"});
	$("#province").change(function(){
		$.post("${base}/common/getAreaList", {"pCode":$(this).val()}, function(data) {
			if (data.flag) {
				$("#city").empty();
				$("#city").append("<option value=''>请选择</option>");
				$.each(data.obj, function(i, n){
					$("#city").append("<option value='"+n.code+"'>"+n.cityName+"</option>");
				});
			}
		});
	});
	$("#city").change(function(){
		$.post("${base}/common/getAreaList", {"pCode":$(this).val()}, function(data) {
			if (data.flag) {
				$("#district").empty();
				$("#district").append("<option value=''>请选择</option>");
				$.each(data.obj, function(i, n){
					$("#district").append("<option value='"+n.code+"'>"+n.cityName+"</option>");
				});
			}
		});
	});
	$("#belongDLS").change(function(){
		$.post("${base}/common/getYYBList", {"pId":$(this).val()}, function(data) {
			if (data.flag) {
				$("#belongId").empty();
				$("#belongId").append("<option value=''>请选择</option>");
				$.each(data.obj, function(i, n){
					$("#belongId").append("<option value='"+n.id+"'>"+n.userName+"</option>");
				});
			}
		});
	});
	
	if('${userType}'=="1"){
		$("#belongId").change(function(){
			$.post("${base}/common/getYWYNo", {"userId":$(this).val()}, function(data) {
				if (data.flag) {
					$("#tjrNo").val(data.obj);
				}
			});
		});
	}
	
	 $('.dropify').dropify({
     	messages: {
		        'default': '点击或拖拽文件到这里',
		        'replace': '点击或拖拽文件到这里来替换文件',
		        'remove':  '移除文件',
		        'error':   '对不起，你上传的文件太大了',
		    }
     });
     // Used events
     drEvent = $('#cardIcon_dropify').dropify();
     drEvent.on('dropify.afterClear', function(event, element) {
     	$("#cardIcon").val("");
     });

     drEvent.on('dropify.errors', function(event, element) {
         console.log('Has Errors');
     });
     
     drEvent2 = $('#regIcon_dropify').dropify();
     drEvent2.on('dropify.afterClear', function(event, element) {
     	$("#regIcon").val("");
     });

     drEvent2.on('dropify.errors', function(event, element) {
         console.log('Has Errors');
     });

	$("#goBack").click(function() {
		$("#main_content").load('${base}/gx/user/list',{"userType":'${userType}'});	        
    });
	
	$("#getCheckCode").click(function() {
		var phone = $.trim($("#phone").val());
		if(phone==""){
    		swal("请输入手机号");
            return;
    	}
    	if (!isPhoneNum(phone)) {
    		swal('请输入正确手机号');
			return;
		}
		settime();
    });
	
	var countdown=10;
    var btn = document.getElementById("getCheckCode");
    function settime() {
      	if (countdown == 0) {
      		btn.innerText="点击重新发送";
            btn.disabled=false;
        	countdown = 10;
        	return false;
      	} else {
        	btn.innerText="重新发送(" + countdown + ")";
            btn.disabled=true;
        	countdown--;
      	}
      	setTimeout(function() {
        	settime();
      	},1000);
    }
	
	function isPhoneNum(str) {
		var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
		if(reg.test(str)) {
			return true;
		} else {
			return false;
		};
	}
	
	$("#submit").click(function() {
	
		var province = $.trim($("#province").val());
		var city = $.trim($("#city").val());
		var district = $.trim($("#district").val());
		var userLevel = $.trim($("#userLevel").val());
		var belongId = $.trim($("#belongId").val());
		var userName = $.trim($("#userName").val());
		var password = $.trim($("#password").val());
		var phone = $.trim($("#phone").val());
		var checkCode = $.trim($("#checkCode").val());
		var cardNo = $.trim($("#cardNo").val());
		var realName = $.trim($("#realName").val());
		var regNo = $.trim($("#regNo").val());
		var regMain = $.trim($("#regMain").val());
		var userType = '${userType}';
    	if(province==""){
    		swal("请选择所属省");
            return;
    	}
    	if(city==""){
    		swal("请选择所属市");
            return;
    	}
    	if(district==""){
    		swal("请选择所属区县");
            return;
    	}
    	if(userType=="1"){
    		if(belongId==""){
        		swal("请选择所属业务员");
                return;
        	}
    		if(userName==""){
        		swal("请输入用户名");
                return;
        	}
    	}
    	if(userType=="2"){
    		if(userLevel==""){
        		swal("请选择代理级别");
                return;
        	}
    		if(userName==""){
        		swal("请输入用户名");
                return;
        	}
    	}
    	if(userType=="4"){
    		if(belongId==""){
        		swal("请选择所属代理商");
                return;
        	}
    		if(userName==""){
        		swal("请输入营业部名称");
                return;
        	}
    	}
    	if(userType=="5"){
    		if(belongId==""){
        		swal("请选择所属营业部");
                return;
        	}
    		if(userName==""){
        		swal("请输入业务员用户名");
                return;
        	}
    	}
    	if(password==""){
    		swal("请输入密码");
            return;
    	}
    	if(phone==""){
    		swal("请输入手机号");
            return;
    	}
    	if (!isPhoneNum(phone)) {
    		swal('请输入正确手机号');
			return;
		}
    	<#if obj??>
    	<#else>
    	if(checkCode==""){
    		swal("请输入验证码");
            return;
    	}
    	</#if>
    	if(cardNo==""){
    		swal("请输入身份证号");
            return;
    	}
    	if(userType=="2"){
    		if(realName==""){
        		swal("请输入真实姓名");
                return;
        	}
    	}
    	if(userType=="4"){
    		if(realName==""){
        		swal("请输入营业部负责人");
                return;
        	}
    	}
    	if(regNo==""){
    		swal("请输入户口本号");
            return;
    	}
    	if(regMain==""){
    		swal("请输入户主姓名");
            return;
    	}
    	//获取数据
		drEvent = $("#cardIcon_dropify").dropify();
	    drEvent = drEvent.data('dropify');
	    if((drEvent.file.object !=null )){
	    	var infoIcon = drEvent.callBackBase64;
	    	infoIcon = infoIcon.substring(infoIcon.indexOf("base64")+7);
	    	$("#cardIcon").val(infoIcon);
	    }else{
	    	if($("#cardIcon").val()==""){
	    		swal("请上传身份证图片");
	            return;
	    	}
	    }
	    drEvent2 = $("#regIcon_dropify").dropify();
	    drEvent2 = drEvent2.data('dropify');
	    if((drEvent2.file.object !=null )){
	    	var infoIcon = drEvent2.callBackBase64;
	    	infoIcon = infoIcon.substring(infoIcon.indexOf("base64")+7);
	    	$("#regIcon").val(infoIcon);
	    }else{
	    	if($("#regIcon").val()==""){
	    		swal("请上传户口本图片");
	            return;
	    	}
	    }
        $("#postForm").ajaxSubmit(function(data) {
    	 	if (data.flag) {
    	 		swal(data.msg, "", "success");
				$("#main_content").load('${base}/gx/user/list',{"userType":'${userType}'});
    	 	} 
    	 	else {
    	 		swal(data.msg, "", "error");
    	 	}
    	});
	});
});
</script>